package com.wwp.tbshop.view.fragment.category;

import android.os.SystemClock;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.wwp.tbshop.model.bean.CategoryInfo;
import com.wwp.tbshop.model.bean.CategoryTempBean;
import com.wwp.tbshop.model.bean.CategoryVo;
import com.wwp.tbshop.util.Constant;
import com.wwp.tbshop.view.adapter.OtherRvAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 楠GG on 2017/6/15.
 */

public class OtherFragment extends CategoryBaseFragment {

    private OtherRvAdapter mOtherRvAdapter;
    private List<CategoryTempBean> mDatas = new ArrayList<>();
    private List<CategoryInfo> mCategoryInfoList = new ArrayList<>();

    @Override
    protected View onPostExcute() {
        RecyclerView rv = new RecyclerView(getActivity());
        rv.setLayoutManager(new LinearLayoutManager(getActivity()));
        mOtherRvAdapter = new OtherRvAdapter(getActivity());
        mOtherRvAdapter.setDatas(mCategoryInfoList);
        rv.setAdapter(mOtherRvAdapter);
        return rv;
    }

    @Override
    public HeimaAsyncTask.Result doInBackground() {
        SystemClock.sleep(Constant.SLEEP_TIME);
        for (CategoryVo.CategoryBean bean  :mMap2.keySet() ) {
            if (mMap2.containsKey(bean) && bean.getParentId() == 1){

                List<CategoryVo.CategoryBean> categoryBeen = mMap2.get(bean);
//                mRecommendMap.put(bean.getName(), categoryBeen);
                if(categoryBeen.size() != 0) {
                    List<CategoryInfo> transfore = transfore(bean, categoryBeen);
                    mCategoryInfoList.addAll(transfore);
                }
            }
        }
        //设置数据
//        initTempData();
        return HeimaAsyncTask.Result.SUCCESS;
    }

    private void initTempData() {
        mDatas.clear();
        int count = 0;
        for (int i = 0; i < 8; i++) {
            CategoryTempBean tempBean = new CategoryTempBean();
            if (i % 3 == 0) {
                tempBean.type = CategoryTempBean.TYPE_TITLE;
                tempBean.title = "标题" + (count ++);
            }else {
                tempBean.type = CategoryTempBean.TYPE_NORMAL;
                tempBean.title = "标题" + count;
            }
            tempBean.name1 = "男装" + i;
            tempBean.name2 = "女装" + i;
            tempBean.name3 = "推荐" + i;
            mDatas.add(tempBean);
        }
    }
}
